package app.fugema.shop.main.order.view;

import com.base.common.netBeanPackage.LiveDataWrapper;
import com.base.common.utils.UIUtils;
import com.base.common.view.adapter.MyGridLayoutManager;
import com.base.common.view.adapter.ada.GeneralRecyclerAdapter;
import com.base.common.view.base.BaseTitleActivity;
import com.base.common.viewmodel.BaseViewObserver;
import com.jeremyliao.liveeventbus.LiveEventBus;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;
import app.fugema.shop.R;
import app.fugema.shop.constants.AppConstants;
import app.fugema.shop.databinding.ActivityMiniShopBinding;
import app.fugema.shop.main.goods.model.GoodsPageBean;
import app.fugema.shop.main.goods.vm.GoodsVM;
import app.fugema.shop.main.home.adapter.HomeGoodsItemBaseItemMultiType;
import app.fugema.shop.main.order.adapter.PayResultTitleItemType;
import app.fugema.shop.main.order.model.OrderPayResultBean;

public class PayResultActivity extends BaseTitleActivity<ActivityMiniShopBinding, GoodsVM>
{

    public static void start(Context context)
    {
        Intent intent = new Intent(context, PayResultActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mini_shop);
    }

    @Override
    protected int getStatusBarColor()
    {
        return R.color.redColor;
    }

    private GeneralRecyclerAdapter adapter;
    private LinearLayoutManager mGridLayoutMgr;
    @Override
    protected void initNotificationReceipt() {
        super.initNotificationReceipt();
        LiveEventBus.get(AppConstants.EventKey.PET_SELECT, Object.class).observe(this, new Observer<Object>() {
            @Override
            public void onChanged(Object listBean) {

            }
        });
    }

    @Override
    protected void initView()
    {
        super.initView();
        setCloseImg(R.mipmap.ic_back_white);
        setTitle("支付成功",R.color.white);

        adapter = new GeneralRecyclerAdapter() {
            @Override
            public void initMultiItemType()
            {
                putMultiItemType(  new PayResultTitleItemType() );
                putMultiItemType(new HomeGoodsItemBaseItemMultiType());
            }
        };
        mGridLayoutMgr = new MyGridLayoutManager(getActivity(), 2);
        binding.rvRecyclerView.setLayoutManager(mGridLayoutMgr);

        binding.rvRecyclerView.setAdapter(adapter);

        //回到首页
        /*
        binding.rtvReturnHomePage.setOnClickListener(new OnClickCheckedUtil() {
            @Override
            public void onClicked(View view) {
                PublicGlobal.getToHomePage(-1);
            }
        });
        */
    }


    @Override
    protected void initData()
    {
        OrderPayResultBean payTitele = new OrderPayResultBean();
        payTitele.setStatus(0);
        //您已成功支付￥28000
        payTitele.setPaymoney("支付成功" );
        adapter.addHeaderView(payTitele,0 );


        // 查询推荐商品
        viewModel.getHomeGoodsByPage(1).observe(this, new BaseViewObserver<LiveDataWrapper<GoodsPageBean>>(this) {
            @Override
            protected void onSuccess(LiveDataWrapper<GoodsPageBean> data) {
                adapter.setDataList(data.data.getProduct());

            }

            @Override
            public boolean isEmptyData(LiveDataWrapper<GoodsPageBean> data) {
                return UIUtils.isEmpty(data.data.getProduct());
            }

            @Override
            protected void onEmptyLayout()
            {
                super.onEmptyLayout();
                binding.rvRecyclerView.setVisibility(View.GONE);
            }
        });

    }



    /**
     *  查询推荐
     * @param cateId
     */
    private void queryTuiJianGoods(String cateId)
    {

    }


}
